#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main() {
	/* file handler */
	int fd;
	char buff[64];

	fd = open("hello.txt",O_RDWR);

	printf("file handler %d\n", fd);
	if(fd == -1){
		printf("open file error\n");

		printf("next create file\n");
		fd = open("hello.txt",O_RDWR | O_CREAT, 0x600);
		if(fd > 0){
			printf("create file Success\n");
		}
	}else{
		read(fd, buff, 50);
		printf("%s\n", buff);
	}

	sprintf(buff,"%s", "hello world!");

	write(fd, buff, strlen(buff));

	close(fd);
	return 0;
}
